<!DOCTYPE html>
<html lang="en">
<head>

    <!-- 页面meta -->

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>去查寝主页</title>

    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">

    <!-- 引入样式 -->

    <link rel="stylesheet" href="../plugins/elementui/index.css">

    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">

    <link rel="stylesheet" href="../css/style.css">

</head>

<body class="hold-transition">

<div id="app">
    <div class="app-container">

        <center>
            <el-button type="primary" plain @click="myself">宿舍人员信息</el-button>
            <el-button type="primary" plain @click="leaves">请假</el-button>
            <el-button type="primary" plain @click="helperCheck">去查寝</el-button>
            <el-button type="primary" plain @click="checkDorm">我的查寝信息</el-button>
            <el-button type="primary" plain @click="checknotice">查看通告</el-button>
            <el-button type="danger" plain @click="tc">退出登陆</el-button>
        </center>
        <div class="box">
            <!--stripe highlight-current-row/-->
            <el-table size="small" current-row-key="id" :data="dataList" >

                <el-table-column prop="sid" align="center" label="学生编号" hidden></el-table-column>
                <el-table-column prop="hid" label="助手编号" align="center" v-if="false">
                    <template slot-scope="scope" >
                      <input v-model="scope.row.hid">
                    </template>
                </el-table-column>
                <el-table-column prop="sname" label="姓名" align="center"></el-table-column>
                <el-table-column prop="sex" label="性别" align="center"></el-table-column>
                <el-table-column prop="dormitory" label="宿舍" align="center"></el-table-column>
                <el-table-column prop="checkState" label="状态" align="center">
                    <template slot-scope="scope">
                    <el-select  placeholder="请选择查寝状态" v-model="scope.row.checkState">
                    <el-option label="" value=""></el-option>
                    <el-option label="已归" value="已归"></el-option>
                    <el-option label="未归" value="未归"></el-option>
                    </el-select>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center" width="180px">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleAdd(scope.row)">点名</el-button>
                    </template>
                </el-table-column>

            </el-table>

            <center>
                <div class="block">
                    <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-sizes="[2, 5, 10, 15]"
                            :page-size="pagination.pageSize"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="pagination.total">
                    </el-pagination>
                </div>
            </center>

        </div>

    </div>
</div>

</body>

<!-- 引入组件库 -->

<script src="../js/vue.js"></script>

<script src="../plugins/elementui/index.js"></script>

<script type="text/javascript" src="../js/jquery.min.js"></script>

<script src="../js/axios-0.18.0.js"></script>

<script>
    var vue = new Vue({
        el: '#app',
        data:{
            dataList: [],//当前页要展示的列表数据
            dialogFormVisible: false,//添加表单是否可见
            dialogFormVisible4Edit:false,//编辑表单是否可见
            dialogFormVisibleBorrow:false, //编辑借书表单是否可见
            hid: undefined,
            helperState:undefined,
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:2,//每页显示的记录数
                total:0,//总记录数
            },
            total:'',
        },

        //钩子函数，VUE对象初始化完成后自动执行
        created(){
            this.getSession();
        },
        mounted() {
            setTimeout(()=>{//不延时没拿到sid就执行了
                this.getHelperState();
            },50)
        },

        methods: {
            //列表
            getAll() {
                axios.get("http://localhost:80/checkdorm/checkStudent",{
                    params:{
                        pageNum: this.pagination.currentPage,
                        pageSize: this.pagination.pageSize,
                    }
                }).then(res=>{
                    this.dataList=res.data.data.records;
                    this.pagination.total=res.data.data.total
                })

            },
            //获得session
            getSession(){
                axios.get("http://localhost:80/checkdorm/getSession").then(res=>{
                    if (res.data.data==null){
                        this.$message.error(res.data.msg)
                        window.location.href="http://localhost:80/xu/pages/studentLogin.html"
                    }
                    this.hid= res.data.data
                    console.log(this.hid)
                })

            },
            getHelperState(){
                axios.get("http://localhost:80/helper/checkIsHelper",{
                    params: {
                        sid: this.hid
                    }
                }).then(res=>{
                    if (res.data.data==false){
                        this.$message.error(res.data.msg)
                    window.location.href="http://localhost:80/xu/pages/myself.html"
                    }
                    this.helperState= 1
                    console.log(this.helperState)
                })
            this.getAll();
            },
            handleAdd(row){
                row.hid=this.hid;
                axios.post("http://localhost:80/checkdorm/addCheck",row).then((res)=>{
                   if (res.data.key==200){
                       this.$message.success(res.data.msg)
                   }
                    if (res.data.key==500){
                        this.$message.error(res.data.msg)
                    }
                })
            },
            handleCurrentChange(val){
                this.pagination.currentPage=val;
                this.getAll();
            },
            handleSizeChange(val){
                this.pagination.pageSize=val;
                this.getAll();
            },
            tc() {
                this.$confirm("确定退出账户？","提示",{type:"info"}).then(()=>{
                    axios.post("http://localhost/logout").then((res)=>{
                        window.location.href = '/xu/pages/studentLogin.html'
                    })
                })
            },
            leaves(){
                window.location.href="http://localhost:80/wu/pages/studentLeave.html"
            },
            myself(){
                window.location.href="http://localhost:80/xu/pages/myself.html"
            },
            checknotice(){
                window.location.href="http://localhost:80/xu/pages/stuboard.html"
            },
            checkDorm(){
                window.location.href="http://localhost:80/wu/pages/studentCheckDorm.html"
            },
            helperCheck(){
                window.location.href="http://localhost:80/wu/pages/helperCheck.html"
            }

        }
    })

</script>
</html>